import { ElMessage, MessageType } from "element-plus";

type MessageCallback = () => void;

const showMessage = (
  msg: string,
  callback?: MessageCallback,
  type?: MessageType
) => {
  ElMessage({
    type,
    message: msg,
    duration: 3000,
    onClose: () => {
      callback?.();
    },
  });
};

const message = {
  error: (msg: string, callback?: MessageCallback) => {
    showMessage(msg, callback, "error");
  },
  success: (msg: string, callback?: MessageCallback) => {
    showMessage(msg, callback, "success");
  },
  warning: (msg: string, callback?: MessageCallback) => {
    showMessage(msg, callback, "warning");
  },
};

export default message;
